package dyyx;

import java.util.Date;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import dyyx.util.ConfigUtil;
import dyyx.util.RunStatusUtil;
import dyyx.util.WebUtil;

public class AppListener implements ServletContextListener{
	
	public void contextInitialized(ServletContextEvent event) {
		System.out.println(this.getClass().getSimpleName()+".init run,"+new Date());
		
		String webRootDir = event.getServletContext().getRealPath("/");
		System.out.println("webRootDir="+webRootDir);
		
		WebUtil.setWebRootDir(webRootDir);
		
		// The context path of the web application, or "" for the default (root) context
		// The path starts with a "/" character but does not end with a "/" character
		String contextPath = event.getServletContext().getContextPath();
		System.out.println("contextPath="+contextPath);

		WebUtil.setContextPath(contextPath);
		
		ConfigUtil.getAllConfig();
		
		RunStatusUtil.updateStaticInfo("appVersion", Version.getVersion());
		RunStatusUtil.updateStaticInfo("webRootDir",WebUtil.getWebRootDir());
		
		if(contextPath.isEmpty()) {
			RunStatusUtil.updateStaticInfo("contextPath","EMPTY");
		}else{
			RunStatusUtil.updateStaticInfo("contextPath",WebUtil.getContextPath());
		}
		


		System.out.println("startTime="+RunStatusUtil.runStatus.startTime);

    	
	}
	
	public void contextDestroyed(ServletContextEvent event) {
		
	
		System.out.println(this.getClass().getSimpleName()+".contextDestroyed run "+System.currentTimeMillis());
    	
	}
}